package com.cnswhy.cloud.server.core.vo;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

/**
 * 分页对象 Created with IntelliJ IDEA. User: HuangHL Date: 14-4-11 Time: 下午4:17
 */
public class PagerVo<T> implements Serializable
{

    private static final long serialVersionUID = -6878053406541100993L;

    private Integer currentPage; // 页数

    private Integer pageSize = 20; // 每页条数

    private Integer total; // 总条数

    private Double currentCount; // 总页数

    private Integer start;

    private Integer end;

    private Integer size;

    // 分页数据
    private List<T> data;

    public PagerVo()
    {
    }

    public PagerVo(Integer currentPage, Integer pageSize, int total)
    {
        this.total = total;
        this.currentPage = currentPage <= 0 ? 1 : currentPage;
        this.pageSize = pageSize;
        BigDecimal b1 = new BigDecimal(Double.toString(total));
        BigDecimal b2 = new BigDecimal(Double.toString(pageSize));
        this.currentCount = Math.ceil(b1.divide(b2, 10, BigDecimal.ROUND_HALF_UP).doubleValue()); // 总页数
        int start, end;
        end = this.currentPage * pageSize; // 最后条数索引
        // 如果最后索引，大于总条数最后索引
        if (end > total)
        {
            end = total;
        }
        start = (this.currentPage - 1) * pageSize;
        this.start = start;
        this.end = end;
        this.size = pageSize;
    }

    public List<T> getData()
    {
        return data;
    }

    public void setData(List<T> data)
    {
        this.data = data;
    }

    public Integer getCurrentPage()
    {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage)
    {
        this.currentPage = currentPage;
    }

    public Integer getPageSize()
    {
        return pageSize;
    }

    public void setPageSize(Integer pageSize)
    {
        this.pageSize = pageSize;
    }

    public Integer getTotal()
    {
        return total;
    }

    public void setTotal(Integer total)
    {
        this.total = total;
    }

    public Double getCurrentCount()
    {
        return currentCount;
    }

    public void setCurrentCount(Double currentCount)
    {
        this.currentCount = currentCount;
    }

    public Integer getStart()
    {
        return start;
    }

    public void setStart(Integer start)
    {
        this.start = start;
    }

    public Integer getEnd()
    {
        return end;
    }

    public void setEnd(Integer end)
    {
        this.end = end;
    }

    public Integer getSize()
    {
        return size;
    }

    public void setSize(Integer size)
    {
        this.size = size;
    }

}
